package com.test.mywebtest.test;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.test.mywebtest.util.PasswordUtil;
import com.test.mywebtest.util.SMS4;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public class UpdateSS {


    public static void main(String[] args) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        File jsonFile = new File("/Users/libin/Downloads/SYS_USER_202507110921.json");
        if(!jsonFile.exists()){
            throw new Exception("wenjianbucunzai");
        }
        Map<String, Object> dataList = objectMapper.readValue(jsonFile, new TypeReference<Map<String, Object>>() {});

        List<Map<String,Object>> data = (List)dataList.get("SYS_USER");


        File outputFile = new File("/Users/libin/Downloads/sql.txt");

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) { // #selectedCode
            for (int i = 0; i < data.size(); i++) {
                Object OBJECT_ID = data.get(i).get("OBJECT_ID");
                Object LOGIN_NAME = data.get(i).get("LOGIN_NAME");
                Object SALT = data.get(i).get("SALT");

                String newPassword = PasswordUtil.encryptPassword((String) LOGIN_NAME, "Gtst@xc!.com.202x", SALT.toString());

                String sql = "UPDATE SYS_USER SET PASSWORD = '" + newPassword + "' WHERE OBJECT_ID='" + OBJECT_ID + "';";
                writer.write(sql);
                writer.newLine(); // 换行

            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        //System.out.println(data.size());
        //for(int i = 0;i<7333;i++){
        //
        //    Object OBJECT_ID = data.get(i).get("OBJECT_ID");
        //    Object LOGIN_NAME = data.get(i).get("LOGIN_NAME");
        //    Object SALT = data.get(i).get("SALT");
        //
        //    String newPassword = PasswordUtil.encryptPassword((String) LOGIN_NAME, "1qaz!QAZ@123",SALT.toString());
        //
        //
        //    //UPDATE 表名 SET 列名=新值 WHERE 条件
        //
        //    System.out.println("UPDATE SYS_USER SET PASSWORD = '" +newPassword + "' WHERE OBJECT_ID='"+OBJECT_ID+"'" );
        //
        //    int a = 0;
        //
        //}
        //System.out.println(a);




    }
}
